package com.guoxue.util;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.guoxue.action.front.BaseAction;
import com.guoxue.domain.PushVo;
import com.guoxue.model.PushMessageVo;
import com.guoxue.service.IPushService;

import redis.clients.jedis.Jedis;
@Component
public class PushMessage extends Thread{
	
	@Resource
	private IPushService pushService;
	@Override
	public void run() {
		while(true){
			Jedis jedis = RedisUtil.getJedis();
			try {
				
				List<PushVo> pushMessageList = pushService.getLastPushList();
				if(pushMessageList.size() > 0){
					PushVo pushVo = pushMessageList.get(0);
					PushMessageVo pushMessage = (PushMessageVo) RedisUtil.unserialize(jedis.get((pushVo.getId()+ "Push").getBytes()));
					if(null != pushMessage){
						BaseAction.PushMessageVo = pushMessage;
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}finally {
				jedis.close();
			}
			try {
				CheckForStaticResources.sleep(1000*60);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
}
